package com.jia.controller;


import com.jia.common.lang.R;
import com.jia.entity.SysUserRole;
import com.jia.service.SysUserRoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-05-23
 */
@RestController
@RequestMapping("/admin/sys/userRole")
@Api(tags = "系统用户角色管理")
public class SysUserRoleController {

    @Autowired
    private SysUserRoleService sysUserRoleService;

    @GetMapping("/list")
    public R list() {
        List<SysUserRole> list = sysUserRoleService.list();
        return R.ok().data("list",list);
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        SysUserRole byId = sysUserRoleService.getById(id);
        return R.ok().data("data",byId);
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id){
        sysUserRoleService.removeById(id);
        return R.ok().message("删除成功");
    }

    @PostMapping("/save")
    public R save(@RequestBody SysUserRole sysUserRole) {
        sysUserRoleService.save(sysUserRole);
        return R.ok().message("新增成功");
    }

    @PutMapping("/update")
    public R update(@RequestBody SysUserRole sysUserRole){
        sysUserRoleService.updateById(sysUserRole);
        return R.ok().message("修改成功");
    }

}

